# $LastChangedDate: 2011-03-06 21:30:11 -0500 (Sun, 06 Mar 2011) $
# LEGAL: COPYRIGHT (C) 2010 JIM E. BROOKS WWW.PALOMINO3D.ORG
# (private to project.cmake)
# Include file for end of project to build.
# Notes:
# - See module.txt
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
# Run tools/checks.sh

IF( PROJECT_BUILD_TYPE MATCHES "Debug" AND UNIX AND NOT NO_CHECKS )
    MESSAGE( STATUS "Running tools/checks.sh" )
    EXECUTE_PROCESS( COMMAND "tools/checks.sh"
                     RESULT_VARIABLE CHECKS_RES
                     OUTPUT_VARIABLE CHECKS_OUT
                     ERROR_VARIABLE CHECKS_ERR )
    MESSAGE( "${CHECKS_OUT}" )
    IF( NOT "${CHECKS_RES}" STREQUAL "0" )
        MESSAGE( FATAL_ERROR "${CHECKS_OUT} ${CHECKS_ERR}" )
    ENDIF()
ENDIF()

#-------------------------------------------------------------------------------
# Build type.
# compiler.cmake instead determines compiler-specific args.

IF( PROJECT_BUILD_TYPE MATCHES "ProfileNoOpt" )
    ADD_DEFINITIONS( -DPROFILE=1 )
    MESSAGE( STATUS "Build: PROFILE_NO_OPT (no optimizations) ${PROJECT_BUILD_TYPE_EXTRA_MSG}" )
ELSEIF( PROJECT_BUILD_TYPE MATCHES "ProfileOpt" ) 
    ADD_DEFINITIONS( -DPROFILE=2 )
    MESSAGE( STATUS "Build: PROFILE_OPT (optimizations) ${PROJECT_BUILD_TYPE_EXTRA_MSG}" )
ELSEIF( PROJECT_BUILD_TYPE MATCHES "Debug" )
    # Don't confuse C++ DEBUG vs. cmake -DDEBUG|-DDEBMIN.
    ADD_DEFINITIONS( -DDEBUG=${DEBUG_LEVEL} )  # supports debug levels such as DEBUG=2
    MESSAGE( STATUS "Build: ${PROJECT_BUILD_TYPE} DEBUG_LEVEL=${DEBUG_LEVEL} ${PROJECT_BUILD_TYPE_EXTRA_MSG}" )
ELSE()  # Release
    # (no special #define)
    MESSAGE( STATUS "Build: ${PROJECT_BUILD_TYPE} ${PROJECT_BUILD_TYPE_EXTRA_MSG}" )
ENDIF()

IF( VERBOSE )
    ADD_DEFINITIONS( -DVERBOSE=1 )
    MESSAGE( STATUS "Build: verbose/logging" )
ENDIF()

#-------------------------------------------------------------------------------
# Build each module.

FOREACH( MODULE ${MODULES} )
    ADD_SUBDIRECTORY( build/${MODULE} )
ENDFOREACH()
